#ifndef ACCOUNT_ACCOUNTMEMBER_H
#define ACCOUNT_ACCOUNTMEMBER_H

#include "profile/profiledata.h"


#include <QObject>
#include <QPixmap>


namespace Network {
class HttpRequest;
}

namespace Account {
class Member : public QObject
{
    Q_OBJECT
public:
    enum MemberType {
        UserType,
        BuddyType,
        UnknownType
    };

public:
    explicit Member(qint64 id, QObject *parent = 0);

    Member(qint64 id,
           const QString &fullName,
           const QString &displayName,
           const QString &avatarUrl,
           QObject *parent = 0);

    Member(const Profile::ProfileData &profile,
           QObject *parent = 0);

private:
    QString m_messageStatusTemp;
    bool m_onlineStatus;
    QImage m_image;
    Profile::ProfileData  m_profile;
    bool m_isProfileEmpty;

Q_SIGNALS:
    void dataChanged(Member *member);

    void profileSet(Member *member);
    void profileAboutToBeUpdated(Member *member);
    void profileUpdated(Member *member);
    void profileGotten(Member *member);

    void onlineStatusSet(Member *member);
    void onlineStatusUpdated(Member *member);

    void updateProfileSuccess(Member *member);

Q_SIGNALS:
    void fullNameChanged(Member *member);
    void displayNameChanged(Member *member);
    void firstNameChanged(Member *member);
    void lastNameChanged(Member *member);
    void messageStatusChanged(Member *member);
    void genderChanged(Member *member);
    void birthdayChanged(Member *member);
    void emailChanged(Member *member);
    void phonesChanged(Member *member);
    void yahooIdChanged(Member *member);
    void googleIdChanged(Member *member);
    void avatarImageAboutToBeChanged(Member *member);
    void avatarImageChanged(Member *member);
    void avatarUrlChanged(Member *member);
    void profileUrlChanged(Member *member);
    void cityChanged(Member *member);

private:
    void init();
    void setConnection() const;

    void updateProfile(const Profile::ProfileData &profile);
    void updateMessageStatus(const QString &text);
    void updateImage(const QImage &image);

private Q_SLOTS:
    void onGetAvatarResponsed(Network::HttpRequest *request);
    void onGetMessageStatusResponsed(Network::HttpRequest *request);
    void onGetProfileResponsed(Network::HttpRequest *request);
    void onPostMessageStatusResponsed(Network::HttpRequest *request);
    void onPostProfileResponsed(Network::HttpRequest *request);

    void onProfileGotten(Member *member);
    void onProfileSet(Member *member);
    void onProfileUpdated(Member *member);

public:
    bool operator < (const Member &another) const;
    static bool compare (const Member *first, const Member *second);

public:
    virtual MemberType type() const = 0;

public:
    void setId(qint64 id);
    qint64 id() const;

    void setFullName(const QString &text);
    const QString &fullName() const;

    void setDisplayName(const QString &text);
    const QString &displayName() const;

    void setAvatarUrl(const QString &url);
    void setMessageStatus(const QString &text);

    void setOnlineStatus(bool status);
    bool onlineStatus() const;

    void setProfile(const Profile::ProfileData &profile);
    const Profile::ProfileData &profile() const;

    QPixmap pixmap() const;
    void setImage(const QImage &image);
    const QImage &image() const;

    void setIsProfileEmpty(bool value);
    bool isProfileEmpty() const;

public:
    void changeFullName(const QString &text);
    void changeDisplayName(const QString &text);
    void changeFirstName(const QString &text);
    void changeLastName(const QString &text);
    void changeStatusMessage(const QString &text);
    void changeBirthday(const QString &text);
    void changePhones(const QString &text);
    void changeGender(const QString &text);
    void changeEmail(const QString &text);
    void changeOnlineStatus(bool state);
    void changeAvatarImage(const QImage &image);
    void changeAvatarUrl(const QString &text);
    void changeProfileUrl(const QString &text);
    void changeYahooId(const QString &text);
    void changeGoogleId(const QString &text);
    void changeCity(const QString &text);

public:
    const QString &firstName() const;
    const QString &lastName() const;
    const QString &birthday() const;
    const QString &email() const;
    const QString &messageStatus() const;
    const QString &avatarUrl() const;
    const QString &profileUrl() const;
    const QString &yahooId() const;
    const QString &googleId() const;
    const QString &city() const;
    int gender() const;

public:
    void postGetAvatarRequest();
    void postGetMessageStatusRequest();
    void postGetProfileRequest();
    void postPostMessageStatusRequest(const QString &messageStatus);
    void postPostProfileRequest(const QString &fullName,
                                const QString &email,
                                const QString &gender,
                                const QString &birthday);
    void startRequestData();
};

} // namespace Account

#endif // ACCOUNT_ACCOUNTMEMBER_H
